import io.lettuce.core.RedisClient;
import io.lettuce.core.api.StatefulRedisConnection;


import java.util.Set;

public class RedisTestSortedSet {
    RedisClient redisClient;
    StatefulRedisConnection<String, String> connection;

    public void link(){
        redisClient = RedisClient.create("redis://localhost");
        connection = redisClient.connect();
        System.out.println("连接");

    }


    public void addSet(String key,String value){

        connection.sync().sadd(key,value);
        Set<String> setTest = connection.sync().smembers(key);
        for(String s : setTest){
            System.out.println(s);
        }
    }

    public void delSet(String key){
        Set<String> setTest = connection.sync().smembers(key);
        for(String s : setTest){
            if (key.equals("")){
                System.out.println("删除成功");
                System.out.println(s);
            }

        }
        connection.sync().srem("setTest","test1");
        setTest = connection.sync().smembers("setTest");
        for(String s : setTest){
            System.out.println(s);
        }
    }


    public void getSet(String key){
        Set<String> setTest = connection.sync().smembers(key);
        for(String s : setTest){
            System.out.println(s);
        }
    }


    public void finish(){
        connection.close();
        redisClient.shutdown();
        System.out.println("结束");
    }

    public static void main(String[] args) {
        RedisTestSortedSet redisTestSortedSet=new RedisTestSortedSet();
        redisTestSortedSet.addSet("02","zhangsan");

        redisTestSortedSet.getSet("01");
        redisTestSortedSet.delSet("01");
        redisTestSortedSet.getSet("01");
        redisTestSortedSet.finish();

    }
}
